<?php

    use think\helper\Str;
    use think\facade\Config;
    use think\facade\Db;
    use think\facade\Session;
    use think\facade\View;

    /**
     * 检测会员是否登录
     * @return integer 0/管理员ID
     */
    function is_user_login()
    {
        $user = Session::get('user_auth');
        if (empty($user)) {
            return 0;
        } else {
            return Session::get('user_auth_sign') == data_auth_sign($user) ? $user['user_id'] : 0;
        }
    }

    /**
     * 保存前台用户行为
     * @param string $remark 日志备注
     */
    function insert_user_log($uid,$remark)
    {
        if (session('?user_auth')) {
            Db::name('user_log')->insert([
                'user_id'     => $uid,
                'ip'          => request()->ip(),
                'url'         => request()->url(true),
                'method'      => request()->method(),
                'type'        => request()->type(),
                'param'       => json_encode(request()->param()),
                'remark'      => $remark,
                'create_time' => time(),
            ]);
        }
    }

    //获取用户ID
    function UserId()
    {
        $info = session('user_auth.user_id');
        return $info;
    }
